﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace UserLoginModule.Views.UserLoginView
{
    public partial class UserLoginView : UserControl, IUserLoginView
    {
        public UserLoginView()
        {
            InitializeComponent();
        }

        #region IUserLoginView Members

        public void SetModel(IUserLoginPresentationModel model)
        {
            this.DataContext = model;
            model.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(model_PropertyChanged);
        }

        void model_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            if (e.PropertyName == "ISOK")
            {
                Current.Tab.SelectedItem = Current.Tab.Items[1];
                Uinfo.DataContext = Current.User;
                Ulogin.Visibility = Visibility.Collapsed;
                Uinfo.Visibility = Visibility.Visible;
                foreach( TabItem  item in  Current.Tab.Items)
                {
                    if (Current.Tab.Items.IndexOf(item) > 0)
                    {
                        item.IsEnabled = true;
                    }
                }
                //((TabItem)Current.Tab.Items[1]).IsEnabled = true;
                //((TabItem)Current.Tab.Items[2]).IsEnabled = true;
                //((TabItem)Current.Tab.Items[3]).IsEnabled = true;
                //((TabItem)Current.Tab.Items[4]).IsEnabled = true;
                //((TabItem)Current.Tab.Items[5]).IsEnabled = true;
            }
        }

        #endregion

        private void Login_Click(object sender, RoutedEventArgs e)
        {
            IUserLoginPresentationModel model = (IUserLoginPresentationModel)this.DataContext;
            model.Login();
            
        }

        private void Loginout_Click(object sender, RoutedEventArgs e)
        {
            Ulogin.Visibility = Visibility.Visible;
            Uinfo.Visibility = Visibility.Collapsed;
            UserName.Text = "";
            UserPassword.Password = "";
            foreach (TabItem item in Current.Tab.Items)
            {
                if (Current.Tab.Items.IndexOf(item) > 0)
                {
                    item.IsEnabled = false;
                }
            }
            //((TabItem)Current.Tab.Items[1]).IsEnabled = false;
            //((TabItem)Current.Tab.Items[2]).IsEnabled = false;
            //((TabItem)Current.Tab.Items[3]).IsEnabled = false;
            //((TabItem)Current.Tab.Items[4]).IsEnabled = false;
            //((TabItem)Current.Tab.Items[5]).IsEnabled = false;
        }
    }
}
